<?php
session_start();
require_once("../models/Request.php");
class ViewRequestController{
	var $requests;
	function requestList(){
		$request = new Request;
		$request->connect();
		$this->requests=$request->getList();
		$i=0;
		while(isset($this->requests[$i])){
		?>
			<input type="checkbox" id=box<?php echo $i;?> value=<?php echo $this->requests[$i]['id'];?> /><a href="#" onclick="viewRequest(<?php echo $this->requests[$i]['id'];?>)"><?php echo $this->requests[$i]['unit'];?></a><br />
		<?php
			$i++;
		}
		if($i>0){
		?>
			<input type="button" value="Delete" onclick="deleteRequest()" />
		<?php
		}
		else{
			echo "There are no requests.";
		}
	}
	
	function requestRequest($id){
		$request = new Request;
		$request->connect();
		$requestMessage = $request->getRequest($id);
		echo "Unit: ".$requestMessage['unit'];
		echo $requestMessage['message'];
	}
	

	

}

	$a = new ViewRequestController;
	if(!isset($_REQUEST['id'])){
		$a->requestList();
	}
	else{
		$a->requestRequest($_REQUEST['id']);
	}
?>